//------------------------------------------------------------------------------
#include <QDate>
#include "CMyTableWidgetItem.h"
//------------------------------------------------------------------------------
CMyTableWidgetItem::CMyTableWidgetItem(const QString &text, QVariant::Type typeColonne) : QTableWidgetItem(text, Type)
{
	_typeColonne=typeColonne;
	setAlignment();
}
//------------------------------------------------------------------------------
CMyTableWidgetItem::CMyTableWidgetItem(const QVariant &field) : QTableWidgetItem(field.toString(), Type)
{
	_typeColonne=field.type();
	setAlignment();
}
//------------------------------------------------------------------------------
bool CMyTableWidgetItem::operator<(const QTableWidgetItem &other) const
{
	QDate d1, d2;
	
	switch(_typeColonne)
	{
		case QVariant::Double:
		case QVariant::Int: 	
		case QVariant::Bool: 	
		case QVariant::LongLong: 	
		case QVariant::UInt: 	
		case QVariant::ULongLong: 	
			return text().toDouble() < other.text().toDouble();
		case QVariant::Date: 	
		case QVariant::DateTime: 	
		case QVariant::Time: 	
			d1=QDate::fromString(text(), "dd/MM/yyyy");
			d2=QDate::fromString(other.text(), "dd/MM/yyyy");
			if(!d1.isValid())
			{
				return text() < other.text();
			}
			
			return d1 < d2;
		default:
			return text() < other.text();
	}
}
//------------------------------------------------------------------------------
void CMyTableWidgetItem::setAlignment(void)
{
	switch(_typeColonne)
	{
		case QVariant::Double:
		case QVariant::Int: 	
		case QVariant::Bool: 	
		case QVariant::LongLong: 	
		case QVariant::UInt: 	
		case QVariant::ULongLong: 	
		case QVariant::Date: 	
		case QVariant::DateTime: 	
		case QVariant::Time: 	
			setTextAlignment(Qt::AlignRight);
			break;
		default:
			setTextAlignment(Qt::AlignLeft);
			break;
	}
}
//------------------------------------------------------------------------------